/***
 * $HeadURL: http://gstestbbs.googlecode.com/svn/trunk/sfmforum/src/main/java/com/sfmforum/core/util/config/SfmForumManager.java $
 * 
 **/
package com.sfmforum.core.util.config;

import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/***
 * @author $Author: nathanliaogs@gmail.com $
 * @version $Revision: 22 $
 * @modified $Date: 2012-03-25 16:14:59 +0000 (Sun, 25 Mar 2012) $
 * 
 **/
public class SfmForumManager {
	private static Log log = LogFactory.getLog(SfmForumManager.class);

	private static Properties properties;

	static {
		properties = new Properties();
		InputStream is = SfmForumResourcesLoader
				.loadResourcesToInputStream("sfmforum.properties");
		if (is == null) {
			log.error("can not load sfmforum.properties file, please check!");
		} else {
			try {
				properties.load(is);
			} catch (Exception e) {
				log.error("can not load sfmforum.properties file, please check!");
			}
		}
	}

	public static Locale getLocale() {
		String stringLocal = properties.getProperty("logger.default.language");
		Locale locale = Locale.getDefault();
		if (stringLocal != null) {
			if (stringLocal.length() == 5 && stringLocal.indexOf("-") == 2) {
				locale = new Locale(stringLocal.substring(0, 2),
						stringLocal.substring(3));
			} else if (stringLocal.length() == 2) {
				locale = new Locale(stringLocal);
			}
		}
		return locale;
	}
}
